package variabilitysmelldetection.measurement.measures.component;

import java.util.List;

import variabilitysmelldetection.measurement.measures.Measure;
import variabilitysmelldetection.measurement.measures.method.CyclomaticComplexity;
import variabilitysmelldetection.measurement.models.ComponentItem;
import variabilitysmelldetection.measurement.models.MethodItem;



public class WeightedMethodsPerClass extends Measure {

	public WeightedMethodsPerClass() {
		super("Weighted Methods Per Class", "WMC");
	}

	@Override
	public void measure(List<ComponentItem> items) {
		for (ComponentItem classe : items) {
			measure(classe);
		}
	}	

	private void measure(ComponentItem componentItem) {
		List<MethodItem> methods = componentItem.getMethods();
		int value = 0;
		for (MethodItem m : methods) {

			Measure measure = m.getMeasure(CyclomaticComplexity.class);
			if (measure != null) {
				value += measure.getValue();
			}
		}
		WeightedMethodsPerClass wmc = new WeightedMethodsPerClass();
		wmc.setValue(value);
		componentItem.addMeasure(wmc);
	}
}
